//给vue添加一个全局属性
Vue.prototype.$http=axios;
//配置axios的全局基本路径
axios.defaults.baseURL='http://localhost:80';
//1 使用axios前置拦截器，让所有的请求都携带uToken
axios.interceptors.request.use(config=>{
    //携带token
    let uToken = localStorage.getItem("token");
    if(uToken){
        config.headers['U-TOKEN']=uToken;
    }
    return config;
},error => {
    Promise.reject(error);
});
//2 使用axios后置拦截器，处理没有登录请求
axios.interceptors.response.use(result=>{
    console.log(result.data+"jjjjjjj");
    let data = result.data;
    if(data.state===0){
        localStorage.removeItem("token");
        localStorage.removeItem("loginUser");
    }
    if(!data.success && data.msg==="noUser")
        location.href = "/login.html";
    return result;
},error => {
    Promise.reject(error);
});

//获取请求?后面的参数
function getRequest() {
    var url = location.search; //获取url中"?"符后的字串
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
        var str = url.substr(1);
        strs = str.split("&");
        for(var i = 0; i < strs.length; i ++) {
            theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
        }
    }
    return theRequest;
}
Vue.prototype.fdfsUrl = "http://121.37.194.36";